#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<vector<int>> a;
    vector<vector<int>> b;
    int Ra, Ca, Rb, Cb;
    cin >> Ra >> Ca;
    for (int i = 0; i < Ra; i++) {
        vector<int> temp;
        int v;
        for (int j = 0; j < Ca; j++) {
            cin >> v;
            temp.push_back(v);
        }
        a.push_back(temp);
    }
    cin >> Rb >> Cb;
    for (int i = 0; i < Rb; i++) {
        vector<int> temp;
        int v;
        for (int j = 0; j < Cb; j++) {
            cin >> v;
            temp.push_back(v);
        }
        b.push_back(temp);
    }
    if (Ca != Rb) {
        cout << "Error: " << Ca << " != " << Rb << endl;
        return 0;
    }
    cout << Ra << " " << Cb << endl;
    for (int row = 0; row < Ra; row++) {
        for (int col = 0; col < Cb; col++) {
            int v = 0;
            for (int k = 0; k < Ca; k++) {
                v += a[row][k] * b[k][col]
            }
            cout << v << " ";
        }
        cout << endl;
    }
    return 0;
}